package com.am.lottery

import androidx.compose.desktop.ui.tooling.preview.Preview
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.window.Window
import androidx.compose.ui.window.WindowPosition
import androidx.compose.ui.window.WindowState
import androidx.compose.ui.window.application
import cafe.adriel.voyager.navigator.CurrentScreen
import cafe.adriel.voyager.navigator.Navigator
import coil3.compose.rememberAsyncImagePainter
import com.am.lottery.db.Db
import com.am.lottery.view.list.ListView
import com.am.lottery.view.menu.menus
import com.sun.tools.javac.Main
import org.jetbrains.compose.resources.ExperimentalResourceApi
import org.jetbrains.compose.resources.InternalResourceApi
import org.slf4j.Logger
import org.slf4j.LoggerFactory

private val logger: Logger = LoggerFactory.getLogger(Main::class.java)

@Composable
@Preview
fun App() {
    MaterialTheme {
        Navigator(ListView) {
            Row(modifier = Modifier.fillMaxSize()) {
                menus()
                Column {
                    CurrentScreen()
                }
            }
        }
    }
}

@OptIn(InternalResourceApi::class, ExperimentalResourceApi::class)
fun main() = application {
    Db.init()
    Window(
        title = "大乐透",
        onCloseRequest = ::exitApplication,
        icon = rememberAsyncImagePainter(
            model = "https://www.ruanxuefeng.com/source/lottery/logo.png",
        ),
        state = WindowState(
            position = WindowPosition.Aligned(
                alignment = Alignment.Center
            ),
        )
    ) {
        App()
    }
}

